package com.bw.ods;

import com.alibaba.ververica.cdc.connectors.mysql.MySQLSource;
import com.alibaba.ververica.cdc.connectors.mysql.table.StartupOptions;
import com.alibaba.ververica.cdc.debezium.DebeziumSourceFunction;
import com.bw.MyDebeziumDeserializationSchema;
import com.bw.MyKafkaUtil;
import org.apache.flink.core.fs.Path;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.CheckpointConfig;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

public class Test1 {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env=StreamExecutionEnvironment.createLocalEnvironment();
        env.setParallelism(1);



        // CDC采集数据
        // sudo vim /etc/my.cnf
        // sudo systemctl restart mysqld
        DebeziumSourceFunction<String> mysqlSource= MySQLSource.<String>builder()
                .hostname("hadoop102")
                .port(3306)
                .username("root")
                .password("123456")
                .databaseList("tms01")
                .startupOptions(StartupOptions.initial())  //全量
//                .startupOptions(StartupOptions.latest())   //增量
                .deserializer(new MyDebeziumDeserializationSchema())
                .build();

        // 加入到flink source
        DataStreamSource<String> mysqlDS=env.addSource(mysqlSource);

        mysqlDS.print();
        mysqlDS.addSink(MyKafkaUtil.getKafkaProducer("tms_ods_yk9"));
        env.execute();

    }

}
